﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Drawing;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows;

namespace Hugo
{
    class HoldProgressIndicator
    {
        private const int MAX_PROGRESS_SIZE = 175;
        int offst = -3;
        private Ellipse e;
        
        private static HoldProgressIndicator instance;

        public static HoldProgressIndicator getInstance() {
            if (instance == null) {
                instance = new HoldProgressIndicator();
            }
            return instance;
        }

        private HoldProgressIndicator()
        {
            e = new Ellipse();
            e.Fill = new SolidColorBrush(GlobalSettings.ProgressColor);
            MainWindow.getInstance().mainCanvas.Children.Add(e);
            Canvas.SetLeft(e, 0);
            Canvas.SetTop(e, 0);
            size = 0;
        }

        int size;
        System.Windows.Point location;

        public void setProgressAmount(int progress, int of)
        {
            size = (int) Math.Ceiling((((double)progress) / of) * MAX_PROGRESS_SIZE);
            resizeOnCenter(e, location, size);
        }

        internal void setProgressLocation(System.Windows.Point p)
        {
            this.location = p;
            setProgressAmount(0, 1);
        }

        private void resizeOnCenter(Ellipse r, System.Windows.Point p, int size)
        {
            e.Width = size;
            e.Height = size;
            Canvas.SetLeft(e,offst+ p.X+(MAX_PROGRESS_SIZE/2)-e.ActualWidth/2);
            Canvas.SetTop(e,offst+p.Y + (MAX_PROGRESS_SIZE / 2) - e.ActualHeight / 2);
        }
    }
}
